
/*
 * GET login.
 */
//http://naholyr.fr/2011/07/authentification-et-websocket-avec-node-js-express-et-socket-io/

//http://runnable.com/UTlPPF-f2W1TAAEY/login-auth-using-sessions-in-express-node-js

var authorization = require('core/authorization');

exports.get = function (req, res) {
    res.render('login', { title: 'Welcome'});
};


exports.post = function (req, res) {
    var login = req.body.login || 'anonymous';
    var password = req.body.password || 'anonymous';

    var user = authorization.get(login, password);
    console.log('login.js. user:' + user);
    if (user == undefined) {
        delete(res.session.user);
        res.send(403);
    } else {
        console.log('login.js. redirect to: ' + '/');
        req.session.user = user;
        res.redirect('/');
    }
};